package com.rom.ratethehell;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MotionEvent;

public class SplashActivity extends Activity {
	private Handler mHandler = new Handler();
	private Object lock = new Object();
	private boolean  hasStarted = false;
	private Runnable loginRunnable = new Runnable() {
	
		@Override
		public void run() {
			proceed();
			
		}
		
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		mHandler.removeCallbacks(loginRunnable);
		mHandler.postDelayed(loginRunnable,3000);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return false;
	}
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		mHandler.removeCallbacks(loginRunnable);
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		mHandler.removeCallbacks(loginRunnable);
		proceed();
		return super.onTouchEvent(event);
	}
	private void proceed() {
		synchronized (lock) {
			if (hasStarted) return;
			hasStarted=true;
			startActivity(new Intent(SplashActivity.this,LoginActivity.class));
			finish();
		}
	}
}
